﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;


public partial class Admin_Config_TopBgM : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { PopulateBJT(); PopulateLevel(); PopulateQQ(); PopulateNavaConfig(); }
    }

    public void PopulateBJT()
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        XmlNode root = xmlDoc.SelectSingleNode("Config");
        XmlNode bgNode = root.SelectSingleNode("TopBgImg");
        if (bgNode == null)
        {
            img.Visible = false;

        }
        else
        {
            img.ImageUrl = bgNode.InnerText;
        }

    }
    protected void btnBJT_Click(object sender, EventArgs e)
    {
        if (fulImg.HasFile)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
            XmlNode root = xmlDoc.SelectSingleNode("Config");
            XmlNode bgNode = root.SelectSingleNode("TopBgImg");
            if (bgNode == null)
            {
                XmlElement objElem = xmlDoc.CreateElement("TopBgImg");
                objElem.InnerText = "/Resource/Config/" + DongDong.Common.Misc.UploadFile(fulImg, "/Resource/Config/", ".jpg.gif.png.jpeg");
                root.AppendChild(objElem);
            }
            else
            {
                XmlElement objElem = (XmlElement)bgNode;
                objElem.InnerText = "/Resource/Config/" + DongDong.Common.Misc.UploadFile(fulImg, "/Resource/Config/", ".jpg.gif.png.jpeg");
            }
            xmlDoc.Save(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
            Page.ClientScript.RegisterStartupScript(this.GetType(), "success1", "<script>alert('顶部背景设置成功');</script>");
            PopulateBJT();
        }
    }

    public void PopulateLevel()
    {


        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        XmlNode root = xmlDoc.SelectSingleNode("Config");
        XmlNode levelode = root.SelectSingleNode("LTLevel");
        if (levelode != null)
        {
            lblLevel.Text = levelode.InnerText + "级";
        }

    }

    protected void btnLevel_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtLevle.Text))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "cancel", "<script>alert('请输入等级');</script>");
            return;
        }
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        XmlNode root = xmlDoc.SelectSingleNode("Config");
        XmlNode LTLevel = root.SelectSingleNode("LTLevel");
        if (LTLevel == null)
        {
            XmlElement objElem = xmlDoc.CreateElement("LTLevel");
            objElem.InnerText = txtLevle.Text;
            root.AppendChild(objElem);
        }
        else
        {
            XmlElement objElem = (XmlElement)LTLevel;
            objElem.InnerText = txtLevle.Text;
        }
        xmlDoc.Save(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        Page.ClientScript.RegisterStartupScript(this.GetType(), "success2", "<script>alert('等级设置成功');</script>");
        PopulateLevel();

    }

    public void PopulateQQ()
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        XmlNode root = xmlDoc.SelectSingleNode("Config");
        XmlNode QQNode = root.SelectSingleNode("QQ");
        if (QQNode != null)
        {
            txtQQ.Text = QQNode.InnerText;
        }

    }


    protected void btnAddQQ_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtQQ.Text))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "cancel3", "<script>alert('请输入qq');</script>");
            return;
        }
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        XmlNode root = xmlDoc.SelectSingleNode("Config");
        XmlNode QQ = root.SelectSingleNode("QQ");
        if (QQ == null)
        {
            XmlElement objElem = xmlDoc.CreateElement("QQ");
            objElem.InnerText = txtQQ.Text;
            root.AppendChild(objElem);
        }
        else
        {
            XmlElement objElem = (XmlElement)QQ;
            objElem.InnerText = txtQQ.Text;
        }
        xmlDoc.Save(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        Page.ClientScript.RegisterStartupScript(this.GetType(), "success3", "<script>alert('QQ设置成功');</script>");
        PopulateQQ();
    }

    public void PopulateNavaConfig()
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        XmlNode root = xmlDoc.SelectSingleNode("Config");
        XmlNode NavaNode = root.SelectSingleNode("Nava");
        if (NavaNode != null)
        {
            string[] NavaConfigs = NavaNode.InnerText.Split(';');
            txtHeight.Text = NavaConfigs[0];
            txtFontFamily.Text = NavaConfigs[1];
            txtFontColor.Text = NavaConfigs[2];
            txtFontSize.Text = NavaConfigs[3];
        }

    }

    protected void btnNavaConfig_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtHeight.Text))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "cancel4", "<script>alert('请输入导航高度');</script>");
            return;
        }
        if (string.IsNullOrEmpty(txtFontFamily.Text))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "cancel5", "<script>alert('请输入导航字体');</script>");
            return;
        }
        if (string.IsNullOrEmpty(txtFontSize.Text))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "cancel6", "<script>alert('请输入导航字体大小');</script>");
            return;
        }

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        XmlNode root = xmlDoc.SelectSingleNode("Config");
        XmlNode Nava = root.SelectSingleNode("Nava");
        if (Nava == null)
        {
            XmlElement objElem = xmlDoc.CreateElement("Nava");
            objElem.InnerText = txtHeight.Text + ";" + txtFontFamily.Text + ";" + txtFontSize.Text;
            root.AppendChild(objElem);
        }
        else
        {
            XmlElement objElem = (XmlElement)Nava;
            objElem.InnerText = txtHeight.Text + ";" + txtFontFamily.Text + ";" + txtFontColor.Text + ";" + txtFontSize.Text;
        }
        xmlDoc.Save(HttpContext.Current.Server.MapPath("/Resource/Config.xml"));
        Page.ClientScript.RegisterStartupScript(this.GetType(), "success4", "<script>alert('前台导航配置成功');</script>");
        PopulateQQ();
    }
}